package com.baijiayun.live.ui.toolbox.custom_webpage;

import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import com.baijiayun.live.ui.R;
import com.baijiayun.live.ui.activity.LiveRoomRouterListener;
import com.baijiayun.liveuibase.utils.DisplayUtils;

/**
 * Created by yongjiaming on 2020/7/13
 * Describe:自定义网页
 */
public class CustomWebPageDialogFragment extends BaseWebViewDialogFragment {

    private LiveRoomRouterListener routerListener;

    @Override
    protected void closeDialogFragment() {
        super.closeDialogFragment();
        routerListener.dismissCustomWebpage();
    }

    public void setRouter(LiveRoomRouterListener liveRoomRouterListener) {
        this.routerListener = liveRoomRouterListener;
    }

    @Override
    protected void setWindowParams(WindowManager.LayoutParams windowParams) {
        int width, height, x, y;
        if (getArguments() != null) {
            width = getArguments().getFloat("width") > 0 && getArguments().getFloat("width") < 1 ?
                    (int) (DisplayUtils.getScreenWidth(getContext()) * getArguments().getFloat("width"))
                    : WindowManager.LayoutParams.MATCH_PARENT;
            height = getArguments().getFloat("height") > 0 && getArguments().getFloat("height") < 1 ?
                    (int) (DisplayUtils.getScreenHeight(getContext()) * getArguments().getFloat("height"))
                    : WindowManager.LayoutParams.MATCH_PARENT;
            x = (int) (DisplayUtils.getScreenWidth(getContext()) * getArguments().getFloat("x"));
            y = (int) (DisplayUtils.getScreenHeight(getContext()) * getArguments().getFloat("y"));
        } else {
            width = WindowManager.LayoutParams.MATCH_PARENT;
            height = WindowManager.LayoutParams.MATCH_PARENT;
            x = 0;
            y = 0;
        }
        windowParams.width = width;
        windowParams.height = height;
        windowParams.gravity = Gravity.TOP | Gravity.LEFT;
        windowParams.x = x;
        windowParams.y = y;
        windowParams.windowAnimations = R.style.BJYLiveBaseSendMsgDialogAnim;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        routerListener = null;
    }
}
